<template>
    <el-container class="content">
        <el-main>
            <el-container class="white-block box full" v-loading="loading">
                <el-header :height="'auto'">
                    <div class="toolbar">
                        <div>
                            <el-input v-model="name" placeholder="请输入姓名" class="input"
                                      size="small"></el-input>
                            <el-button class="primary" @click="getList(1)" size="small">查询</el-button>
                            <el-button class="minor" @click="reset()" size="small">重置</el-button>
                            <el-button @click="dataExport()" size="small">导出
                            </el-button>
                        </div>
                    </div>
                </el-header>
                <el-main class="mt10">
                    <table-example ref="table" :data="tableData" :tableColumn="header" :slotColumns="slotColumns"
                                   :stripe="true">
                        <template slot="operation" slot-scope="scope">
                            <div class="operation">
                                <el-link type="primary" :underline="false" v-if="scope.row.qrCheck==2"
                                         @click="approval(scope.row.id,scope.row.qrCheck,1)">授权
                                </el-link>
                                <el-link type="primary" :underline="false" v-if="scope.row.qrCheck==1"
                                         @click="approval(scope.row.id,scope.row.qrCheck,2)">取消授权
                                </el-link>
                                <!--                                <el-link type="primary" :underline="false">删除</el-link>-->
                            </div>
                        </template>
                        <template slot="password" slot-scope="scope">
                            <span v-if="scope.row.password">{{scope.row.password}}</span>
                            <span v-else>-</span>
                        </template>
                    </table-example>
                </el-main>
                <el-footer :height="'auto'" class="mt20">
                    <page :data="page" @jumpPage="getList"></page>
                </el-footer>
            </el-container>
        </el-main>
    </el-container>
</template>

<script>
    import tableExample from '../components/table'
    import page from '../components/pagination'

    export default {
        data() {
            return {
                name: '', // 姓名
                tableData: [],
                currentList: null,
                header: [
                    {
                        prop: 'managerName',
                        label: '联系人',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'managerPhone',
                        label: '联系方式',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'name',
                        label: '网点名称',
                        minWidth: '150',
                        align: 'center'
                    },
                    {
                        prop: 'operation',
                        label: '操作',
                        align: 'center',
                        minWidth: '100',
                        fixed: 'right'
                    }
                ],
                slotColumns: ['operation'],
                page: {},
                index: 1,
                loading: false
            }
        },
        mounted() {
            this.getList()
        },
        methods: {
            // 获取列表数据
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/getSweepCodeStaff/getSweepPage', {
                    name: this.name,
                    current: this.index || 1,
                    size: 15
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records
                        this.page = result.data
                        delete this.page['records']
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            reset() {
                this.name = ''
                this.getList(1)
            },
            approval(id, state, type) {
                let message, _this = this
                if (type !== 2) {
                    message = '是否对该用户授权'
                } else {
                    message = '是否对该用户取消授权'
                }
                this.$method.messageBox('confirm', message, (action, instance) => {
                    if (action === 'confirm') {
                        _this.$http.post('/getSweepCodeStaff/cancelPower', {
                            id: id,
                            state: state
                        }).then(result => {
                            _this.loading = false
                            if (result.success) {
                                _this.getList()
                                _this.$message({
                                    type: 'success',
                                    message: '状态修改成功!'
                                })
                            }
                        })
                    }
                }, '', false, false)
            },
            dataExport() {
                let params = {
                    name: this.name
                }, url = '/_api/getSweepCodeStaff/getSweepExcel'
                url += '?' + this.$qs.stringify(params)
                window.open(location.origin + url, '_blank')
            }
        },
        components: {
            tableExample,
            page
        }
    }
</script>

<style scoped lang="less">
    .content {
    }
</style>
